﻿using System;
using System.Web;
using Liu_Project.Entity.Admin;

namespace Liu_Project.Web.Admin
{
    public abstract class BasePage : System.Web.UI.Page
    {
        private static EntUser _CurrentUser = null;

        public static Entity.Admin.EntUser CurrentUser
        {
            get
            {
                return _CurrentUser;
            }
            set
            {
                _CurrentUser = value;
                if (_CurrentUser != null)
                {
                    if (!string.IsNullOrWhiteSpace(_CurrentUser.Img))
                    {
                        int index = _CurrentUser.Img.LastIndexOf(".jpg");
                        index = index <= 0 ? 0 : index + 4;
                        _CurrentUser.Img = _CurrentUser.Img.Substring(0, index);
                    }
                    var img = _CurrentUser.Img + "?" + DateTime.Now.ToString("yyyyMMddHHmmss");
                    _CurrentUser.Img = string.IsNullOrWhiteSpace(_CurrentUser.Img) ? "/Admin/images/admin.jpg" : img;
                }
                else
                {
                    //防止页面访问用户属性报错,默认赋值为空
                    _CurrentUser = new EntUser() { };
                }
            }
        }

        public virtual void PageLoad() { }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                CurrentUser = (EntUser)Session["CurrentUser"];

            PageLoad();
        }
    }
}